<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/11/12
 * Time: 17:09
 */
namespace app\admin\controller;
use think\Db;
class Tan extends Base
{
    /*
     * 向导图首页
     */
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $count = Db::name('tan')->count();//计算总页面
            $lists = Db::name('tan')->select();
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$lists]);
        }
        return $this->fetch('tan/index');
    }

    /*
     * 编辑向导图
     */
    public function tanEdit(){
        if(request()->isPost ()){
            extract(input());
            $param = [
                'tan_image'=>$tan_image,
                'tan_update_time'=>date('Y-m-d H:i:s')
            ];
            $res = Db::name('tan')->where('tan_id',$tan_id)->update($param);
            if($res){
                return json(['code'=>200,'msg'=>'修改成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改失败']);
            }
        }
        $data = Db::name('tan')->where('tan_id',input('id'))->find();
        return $this->fetch('tan/tan_edit',['data'=>$data]);
    }
}